//
//  UserConfig.m
//  SSWiFi
//
//  Created by 酷安 @啥也不会啊啊啊啊啊啊  on 2024/1/23.
//

#import "UserConfig.h"
@interface UserConfig()
@property (assign,nonatomic) bool _isLogin;
//@property (assign,nonatomic) bool _isDebug;
@property (strong,nonatomic) NSArray *loginIps;
@end


@implementation UserConfig
static UserConfig* _instance = nil;
+ (instancetype)shareInstance {
    static dispatch_once_t onceToken ;
    dispatch_once(&onceToken, ^{
        _instance = [[super allocWithZone:NULL] init] ;
    }) ;
    return _instance ;
    }
 
 //用alloc返回也是唯一实例
+(id) allocWithZone:(struct _NSZone *)zone {
    return [UserConfig shareInstance] ;
}
//对对象使用copy也是返回唯一实例
-(id)copyWithZone:(NSZone *)zone {
    return [UserConfig shareInstance] ;//return _instance;
}
 //对对象使用mutablecopy也是返回唯一实例
-(id)mutableCopyWithZone:(NSZone *)zone {
    return [UserConfig shareInstance] ;
}


- (void)setIsLogin:(BOOL)isLogin{
    self._isLogin = isLogin;
    if(!isLogin){
        self.api = nil;
    }
    NSLog(@"%@",isLogin ? @"已登录": @"未登录");
}

- (BOOL)isLogin{
    NSLog(@"%@",self._isLogin ? @"已登录": @"未登录");
    return self._isLogin;
}

- (void)setIsDeBug:(BOOL)isDeBug{
//    self._isDebug = isDeBug;
    [[NSUserDefaults standardUserDefaults] setBool:isDeBug forKey:@"isdebug"];
}

- (BOOL)isDeBug{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"isdebug"];
}

- (NSArray *)loginIps{
    if (_loginIps == nil){
        _loginIps =  @[
            @{@"ip":@"192.168.0.1",@"pwd":@"admin"},
            @{@"ip":@"192.168.100.1",@"pwd":@"admin"},
        ];
    }
    return _loginIps;
   
}

+ (NSArray *)loginIps{
    return [[self shareInstance] loginIps];
}

+ (NSArray *)serverPaths{
    NSArray *loginPaths = @[@{
        @"set":@"reqproc/proc_post",
        @"get":@"reqproc/proc_get",
    },@{
        @"set":@"goform/goform_set_cmd_process",
        @"get":@"goform/goform_get_cmd_process",
    },];
    return loginPaths;
}

+ (void)saveLoginIps:(NSArray *)loginIps{
    NSMutableArray *arr = [NSMutableArray array];
    for(NSDictionary *dic in loginIps){
        [arr addObject: @{@"ip":dic[@"ip"],
                          @"pwd":dic[@"pwd"]}];
    }
    [[NSUserDefaults standardUserDefaults] setValue:arr forKey:@"loginIps"];
    
}

+ (void)loadLoginIps{
    NSArray *arr = [[NSUserDefaults standardUserDefaults] valueForKey:@"loginIps"];
    [UserConfig shareInstance].loginIps = arr;
}


@end
